package ma.ensias.tuts.controller;

import javax.validation.Valid;

import ma.ensias.tuts.form.Contact;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class ContactController {
	
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String addContact(@Valid Contact contact, BindingResult result) {
 
		if (result.hasErrors()) {
			return "Add";
		} else {
			return "Done";
		}
		
	}
 
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView displayForm() {
		return new ModelAndView("Add","contact", new Contact());
 
	}
}
